package com.cg.design.graphicdesignpattern.singleton;

/**
 * 售票单例类
 *
 * @program: LeetCode->TicketMaker
 * @description: 售票单例类
 * @author: cg
 * @create: 2022-03-19 15:53
 **/
public class TicketMaker {
    private int ticket = 1000;
    private static TicketMaker singleton = new TicketMaker();

    private TicketMaker() {

    }

    public static TicketMaker getInstance() {
        return singleton;
    }

    /**
     * synchronized是为了在多线程的环境中能够同步
     * @return
     */
    public synchronized int getNextTicketNumber() {
        return ticket++;
    }

}
